﻿@{
    Layout = null;
}
<!doctype html>
<html>
<head>
    <title>场次设置</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="~/Content/bootstrap.css" rel="stylesheet" />
</head>
<body>
    <div class="container">
        <h1>场次设置</h1>
        <div class="row text-center">
            场次选择：
            <select id="matchChoose">
                <option value="0">--请选择--</option>
            </select>
        </div>
        <br />
        <div class="row text-center">
            <div class="col-md-12">
                <span>选手1：</span>
                <select id="player1Add">
                    <option value="0">--请选择--</option>
                </select>&nbsp;&nbsp;
                <span>表演节目：</span>
                <input type="text" name="P1Song" id="player1Song" value="" >
            </div>
        </div>
        <br />
        <div class="row text-center">
            <div class="col-md-12">
                <span>选手2：</span>
                <select id="player2Add">
                    <option value="0">--请选择--</option>
                </select>&nbsp;&nbsp;
                <span>表演节目：</span>
                <input type="text" name="P2Song" id="player2Song" value="" >
            </div>
        </div><br />
        <div class="row text-center">
            <input type="button" id= "playersAdd" name="addPlayer" value="添加" class="center">
        </div>

        <hr />
        <div class="row text-center">
            <h2>比赛详情</h2>
            <table width="100%" border="1" class="text-center" id="matchInfo">
                <tr>
                    <th rowspan="2">比赛场次</th>
                    <th colspan="5">第一名选手</th>
                    <th colspan="5">第二名选手</th>
                    <th rowspan="2">比赛状态</th>
                    <th rowspan="2">操作</th>
                </tr>
                <tr>
                    <th>姓名</th>
                    <th>节目名称</th>
                    <th>得票数</th>
                    <th>评委打分</th>
                    <th>总分</th>

                    <th>姓名</th>
                    <th>节目名称</th>
                    <th>得票数</th>
                    <th>评委打分</th>
                    <th>总分</th>
                </tr>
            </table>
        </div>

    </div>
    <script src="~/Scripts/jquery-1.10.2.js"></script>
    <script src="~/Scripts/bootstrap.js"></script>
    <script>
        $(function () {
           
            //需要加载的数据
            //场次选择
            //$("#matchChoose").val()
            //选手1选择添加
            //$("#player1Add").val()
            //选手2选择添加
            //$("#player2Add") select
            //加载的比赛信息
            //$("#matchInfo").val()
            //选手所唱歌曲
            //$("#player1Song")
            //$("#player2Song")

            //获取选手信息
            $.ajax({
                url: "/Match/GetMatchInfo?Type=1",
                type: "POST",
                async: false,
                dataType: "json",
                success: function (date) {
                    var playerHtml="";
                    for (var item in date) {
                        playerHtml += "<option value='"+date[item].ID+"'>" + date[item].PlayerName + "</option>";
                    }
                    $("#player1Add").append(playerHtml);
                    $("#player2Add").append(playerHtml);
                },
                error: function (date) {
                    alert("getPlayersError" + date);
                }
            });
            //获取Match信息
            $.ajax({
                url: "/Match/GetMatchInfo?Type=2",
                type: "POST",
                async: false,
                dataType: "json",
                success: function (date) {
                    var matchHtml = "";
                    for (var item in date) {
                        matchHtml += "<option value='" + date[item].ID + "'>" + date[item].MatchName + "</option>";
                    }
                    $("#matchChoose").append(matchHtml);
                },
                error: function (date) { }
            });
            //获取比赛详细信息
            $.ajax({
                url: "/Match/GetMatchInfo?Type=3",
                type: "POST",
                async: false,
                dataType: "json",
                success: function (date) {
                    var htmlText="";
                    for (var item in date) {
                        var State;
                        var BtnText;
                        var PuaseState;
                        switch (date[item].BattleFlag) {
                            case '0': State = "未开始"; BtnText = "开始"; PuaseState = "disabled"; break;
                            case '1': State = "正在投票"; BtnText = "停止"; PuaseState = ""; break;
                            case '2': State = "暂停投票"; BtnText = "开始"; PuaseState = "disabled"; break;
                            case '3': State = "结束投票"; BtnText = "开始"; PuaseState = "disabled"; break;
                            default: State = "未知状态";
                        }
                        htmlText +=
                            "<tr>" +
                                "<td>" + date[item].Matchs.MatchName + "</td>" +
                                //第一名选手
                                "<td>" + date[item].FirstPlayer.PlayerName + "</td>" +
                                "<td>" + date[item].FirstSongName + "</td>" +
                                "<td>" + date[item].FirstTickCount + "</td>" +
                                "<td>" + date[item].FirstNeedScore + "</td>" +
                                "<td>" + date[item].FirstScore + "</td>" +
                                //第二名选手
                                "<td>" + date[item].SecondPlayer.PlayerName + "</td>" +
                                "<td>" + date[item].SecondSongName + "</td>" +
                                "<td>" + date[item].SecondTickCount + "</td>" +
                                "<td>" + date[item].SecondNeedScore + "</td>" +
                                "<td>" + date[item].SecondScore + "</td>" +
                                //状态与操作
                                "<td>" + State + "</td>" +
                        "<td><input type='button' onclick='stateChange(" + date[item].ID + ")'  value='" + BtnText + "' />" +
                        "<input type= 'button' onclick='statePause(" + date[item].ID + ")' " + PuaseState + " value= '暂停' /></td>" +
                                    "</tr>";
                    }
                    $("#matchInfo").append(htmlText);
                },
                error: function (date) {
                    alert("getMatchPKInfoError" + date);
                }
            });
            stateChange(22);


        });
        //添加比赛
        $("#playersAdd").click(function () {
            var matchChoose = $("#matchChoose").val();
            var player1Add = $("#player1Add").val();
            var player2Add = $("#player2Add").val();
            var player1Song = $("#player1Song").val();
            var player2Song = $("#player2Song").val();

            if (matchChoose == 0 || player1Add == 0 || player2Add == 0) {
                alert("请选择场次或选手");
                return false;
            } else if (player1Song == "" || player2Song == "") {
                alert("请填写选手表演节目名称");
                return false;
            }
            var data = { matchChoose: matchChoose, player1Add: player1Add, player2Add: player2Add, player1Song: player1Song, player2Song: player2Song };
            $.ajax({
                url: "/Match/Create",
                data: data,
                type: "POST",
                dataType: "JSON",
                success: function () { },
                error: function () { }
            });
            
        });


        //改变状态，开启或关闭
        function stateChange(Id) {
            alert("StateChange" + Id);
        }
        //暂停投票
        function statePause(Id) {
            alert("StatePauese" + Id);
        }
    </script>
</body>
</html>